<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
<link rel="stylesheet" href="__PUBLIC__/admin/css/login.css">
<link href="__PUBLIC__/admin/css/font-awesome.min.css" rel="stylesheet">
<link href="__PUBLIC__/admin/css/animate.min.css" rel="stylesheet">
<script type="text/javascript"
	src="__PUBLIC__/common/js/jquery-2.0.3.min.js"></script>
<script type='text/javascript'>
	function freshVerify() {
		document.getElementById('LAY-user-get-vercode').src = '__CONTROLLER__/verify/'
				+ Math.random();
	}
</script>
</head>
<body layadmin-themealias="default" class="layui-layout-body">
	<div id="lay_app">
		<div class="layadmin-user-login layadmin-user-display-show">
			<div class="layadmin-user-login-main">
				<div class="layadmin-user-login-box layadmin-user-login-header">
					<h2>{$Think.config.WEB_CONFIG.TITLE}</h2>
				</div>
				<div
					class="layadmin-user-login-box layadmin-user-login-body layui-form">
					<div class="layui-form-item">
						<input type="text" name="username" id="lay-user-login-username"
							lay-verify="username" placeholder="用户名" class="layui-input">
					</div>
					<div class="layui-form-item">
						<input type="password" name="password"
							id="LAY-user-login-password" lay-verify="pass" placeholder="密码"
							class="layui-input">
					</div>
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<input type="text" name="vercode" id="LAY-user-login-vercode"
									lay-verify="vercode" placeholder="图形验证码" class="layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<img src='__CONTROLLER__/verify' onClick='freshVerify()'
										title="点击刷新验证码" class="layadmin-user-login-codeimg"
										id="LAY-user-get-vercode">
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<button id="loginBtn" class="layui-btn layui-btn-fluid"
							data-loading-text="<i class='fa fa-spinner fa-spin' style='display: inline-block;'></i>正在登录"
							lay-submit="" lay-filter="LAY-user-login-submit">登 入</button>
					</div>
				</div>
			</div>
			<div class="layui-trans layadmin-user-login-footer">
				<p>{$Think.config.WEB_CONFIG.COPYRIGHT}</p>
			</div>
		</div>
	</div>
	<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
	<script type="text/javascript" src="__PUBLIC__/common/js/button.js"></script>
	<script type="text/javascript">
		layui.config({
			base : '../assets/layui/dist/'
		});
		layui.use([ 'layer', 'form' ], function() {
			var $ = layui.$, form = layui.form, layer = layui.layer;
			form.render();
			form.verify({
				username : function(value, item) {
					if (value == null || value == '') {
						return '用户名不能为空';
					}
					if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$")
							.test(value)) {
						return '用户名不能有特殊字符';
					}
					if (/(^\_)|(\__)|(\_+$)/.test(value)) {
						return '用户名首尾不能出现下划线\'_\'';
					}
					if (/^\d+\d+\d$/.test(value)) {
						return '用户名不能全为数字';
					}
				},
				pass : [ /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格' ],
				vercode : function(value, item) {
					if (value == null || value == '') {
						return '验证码不能为空';
					}
					if (!/^\d+\d+\d$/.test(value)) {
						return '验证码必须是数字';
					}
				}
			});
			form.on('submit(LAY-user-login-submit)', function(obj) {
				$("#loginBtn").button('loading');
				$("input").attr('disabled', 'disabled');
				$.ajax({
					type : "POST",
					data : obj.field,
					url : "{:U('Public/checkLogin')}",
					success : function(res) {
						$("#loginBtn").button('reset');
						$("input").removeAttr('disabled');
						if (res.status == 1) {
							var token = res.token;
							layui.data('cache', {
								key : 'token',
								value : token
							});
							layer.alert(res.info, {
								icon : 1,
								closeBtn : 0
							}, function(index) {
								layer.close(index);
								location.href = res.url;
							});
						} else {
							layer.msg(res.info, {
								icon : 2,
								time : 1500
							});
						}
					},
					error : function() {
						$("#loginBtn").button('reset');
						$("input").removeAttr('disabled');
						layer.msg('请求失败', {
							icon : 2,
							time : 1000
						});
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>